<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 16:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Flight" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%
  String fid = request.getParameter("fid");
  DB_Flight dbFlight = new DB_Flight();
  List<String> findInput = new ArrayList<>();
  List<String> returnList = new ArrayList<>();
  dbFlight.find("fid", fid, returnList);

  if (!returnList.isEmpty()) {
    String starttime = returnList.get(1);
    String endtime = returnList.get(2);
    String takeoffstation = returnList.get(3);
    String arrivalstation = returnList.get(4);
    String boardingtime = returnList.get(5);

    String[] starttimeParts = starttime.split(" ")[0].split("-");
    String[] starttimeTimeParts = starttime.split(" ")[1].split(":");

    String[] endtimeParts = endtime.split(" ")[0].split("-");
    String[] endtimeTimeParts = endtime.split(" ")[1].split(":");

    String[] boardingtimeParts = boardingtime.split(" ")[0].split("-");
    String[] boardingtimeTimeParts = boardingtime.split(" ")[1].split(":");
%>
<!DOCTYPE html>
<html>
<head>
  <title>编辑航班</title>
</head>
<body>
<h2>编辑航班</h2>
<form action="updateFlight.jsp" method="post">
  <input type="hidden" name="fid" value="<%= fid %>">

  <label for="starttimeYear">起飞时间 - 年:</label>
  <select id="starttimeYear" name="starttimeYear">
    <% for (int year = 2024; year <= 2030; year++) { %>
    <option value="<%= year %>" <%= year == Integer.parseInt(starttimeParts[0])? "selected" : "" %>><%= year %></option>
    <% } %>
  </select>
  <select id="starttimeMonth" name="starttimeMonth">
    <% for (int month = 1; month <= 12; month++) { %>
    <option value="<%= String.format("%02d", month) %>" <%= month == Integer.parseInt(starttimeParts[1])? "selected" : "" %>><%= String.format("%02d", month) %></option>
    <% } %>
  </select>
  <select id="starttimeDay" name="starttimeDay">
    <% for (int day = 1; day <= 31; day++) { %>
    <option value="<%= String.format("%02d", day) %>" <%= day == Integer.parseInt(starttimeParts[2])? "selected" : "" %>><%= String.format("%02d", day) %></option>
    <% } %>
  </select>
  <select id="starttimeHour" name="starttimeHour">
    <% for (int hour = 0; hour < 24; hour++) { %>
    <option value="<%= String.format("%02d", hour) %>" <%= hour == Integer.parseInt(starttimeTimeParts[0])? "selected" : "" %>><%= String.format("%02d", hour) %></option>
    <% } %>
  </select>
  <select id="starttimeMinute" name="starttimeMinute">
    <% for (int minute = 0; minute < 60; minute++) { %>
    <option value="<%= String.format("%02d", minute) %>" <%= minute == Integer.parseInt(starttimeTimeParts[1])? "selected" : "" %>><%= String.format("%02d", minute) %></option>
    <% } %>
  </select>
  <select id="starttimeSecond" name="starttimeSecond">
    <% for (int second = 0; second < 60; second++) { %>
    <option value="<%= String.format("%02d", second) %>" <%= second == Integer.parseInt(starttimeTimeParts[2])? "selected" : "" %>><%= String.format("%02d", second) %></option>
    <% } %>
  </select><br>

  <label for="endtimeYear">到达时间 - 年:</label>
  <select id="endtimeYear" name="endtimeYear">
    <% for (int year = 2024; year <= 2030; year++) { %>
    <option value="<%= year %>" <%= year == Integer.parseInt(endtimeParts[0])? "selected" : "" %>><%= year %></option>
    <% } %>
  </select>
  <select id="endtimeMonth" name="endtimeMonth">
    <% for (int month = 1; month <= 12; month++) { %>
    <option value="<%= String.format("%02d", month) %>" <%= month == Integer.parseInt(endtimeParts[1])? "selected" : "" %>><%= String.format("%02d", month) %></option>
    <% } %>
  </select>
  <select id="endtimeDay" name="endtimeDay">
    <% for (int day = 1; day <= 31; day++) { %>
    <option value="<%= String.format("%02d", day) %>" <%= day == Integer.parseInt(endtimeParts[2])? "selected" : "" %>><%= String.format("%02d", day) %></option>
    <% } %>
  </select>
  <select id="endtimeHour" name="endtimeHour">
    <% for (int hour = 0; hour < 24; hour++) { %>
    <option value="<%= String.format("%02d", hour) %>" <%= hour == Integer.parseInt(endtimeTimeParts[0])? "selected" : "" %>><%= String.format("%02d", hour) %></option>
    <% } %>
  </select>
  <select id="endtimeMinute" name="endtimeMinute">
    <% for (int minute = 0; minute < 60; minute++) { %>
    <option value="<%= String.format("%02d", minute) %>" <%= minute == Integer.parseInt(endtimeTimeParts[1])? "selected" : "" %>><%= String.format("%02d", minute) %></option>
    <% } %>
  </select>
  <select id="endtimeSecond" name="endtimeSecond">
    <% for (int second = 0; second < 60; second++) { %>
    <option value="<%= String.format("%02d", second) %>" <%= second == Integer.parseInt(endtimeTimeParts[2])? "selected" : "" %>><%= String.format("%02d", second) %></option>
    <% } %>
  </select><br>

  <label for="takeoffstation">起飞站:</label>
  <input type="text" id="takeoffstation" name="takeoffstation" value="<%= takeoffstation %>" required><br>
  <label for="arrivalstation">到达站:</label>
  <input type="text" id="arrivalstation" name="arrivalstation" value="<%= arrivalstation %>" required><br>

  <label for="boardingtimeYear">登机时间 - 年:</label>
  <select id="boardingtimeYear" name="boardingtimeYear">
    <% for (int year = 2024; year <= 2030; year++) { %>
    <option value="<%= year %>" <%= year == Integer.parseInt(boardingtimeParts[0])? "selected" : "" %>><%= year %></option>
    <% } %>
  </select>
  <select id="boardingtimeMonth" name="boardingtimeMonth">
    <% for (int month = 1; month <= 12; month++) { %>
    <option value="<%= String.format("%02d", month) %>" <%= month == Integer.parseInt(boardingtimeParts[1])? "selected" : "" %>><%= String.format("%02d", month) %></option>
    <% } %>
  </select>
  <select id="boardingtimeDay" name="boardingtimeDay">
    <% for (int day = 1; day <= 31; day++) { %>
    <option value="<%= String.format("%02d", day) %>" <%= day == Integer.parseInt(boardingtimeParts[2])? "selected" : "" %>><%= String.format("%02d", day) %></option>
    <% } %>
  </select>
  <select id="boardingtimeHour" name="boardingtimeHour">
    <% for (int hour = 0; hour < 24; hour++) { %>
    <option value="<%= String.format("%02d", hour) %>" <%= hour == Integer.parseInt(boardingtimeTimeParts[0])? "selected" : "" %>><%= String.format("%02d", hour) %></option>
    <% } %>
  </select>
  <select id="boardingtimeMinute" name="boardingtimeMinute">
    <% for (int minute = 0; minute < 60; minute++) { %>
    <option value="<%= String.format("%02d", minute) %>" <%= minute == Integer.parseInt(boardingtimeTimeParts[1])? "selected" : "" %>><%= String.format("%02d", minute) %></option>
    <% } %>
  </select>
  <select id="boardingtimeSecond" name="boardingtimeSecond">
    <% for (int second = 0; second < 60; second++) { %>
    <option value="<%= String.format("%02d", second) %>" <%= second == Integer.parseInt(boardingtimeTimeParts[2])? "selected" : "" %>><%= String.format("%02d", second) %></option>
    <% } %>
  </select><br>

  <input type="submit" value="更新航班">
</form>
</body>
</html>
<% } else {
  out.println("未找到要编辑的航班");
} %>